package com.itheima.DeptService.impl;

import com.itheima.Dao.impl.LogDaoimpl;
import com.itheima.DeptService.LogService;
import com.itheima.pojo.Dept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
@Component
public class LogServiceimpl implements LogService {

    @Autowired
    private LogDaoimpl logDaoimpl;
    @Override
    public List<Dept> List() {
        List<String> lines=logDaoimpl.list();
        List<Dept> deptList = lines.stream().map(line -> {
            String[] parts = line.split(",");
            Integer id = Integer.parseInt(parts[0]);
            String name = parts[1];
            LocalDateTime updateTime = LocalDateTime.parse(parts[2], DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
            return new Dept(id, name, updateTime);
        }).toList();
         return  deptList;
    }
}
